<?php
	$config = Config::read('config');
	
	// Si han intentado iniciar sesión
	if (Session::isset_data('message'))
	{
		// No mostrar más mensajes
		Session::unset_data('message');
		echo "
			<script type='text/javascript'>
				saySimple('" . ucfirst(_("welcome")) . "', '" . ucfirst(_("cordial greeting")) . " " . Auth::get('account') . "');
			</script>
			";
	}

	if (Auth::is_valid())
	{
		/* Vista parcial de usuario con sesión iniciada */
?>
	<table class="table-login">
		<tr>
			<td><span><?php echo ucfirst(_("user")); ?>:</span></td>
			<td class="td-logout"><?php echo Auth::get('account'); ?></td>
		</tr>
		<tr>
			<td rowspan="3" style="text-align: center;">
				<script type="text/javascript">
				window.addEvent('domready', function()
				{
					
					
					
					
					var options = {
			/*
				upload restrictions
			*/
			
			base: 'fuck/upload.php',
			
			//you cannot upload more than 3 files
			limit: 0,
			
			// Máxima cantidad de archivos que se pueden arrastrar
			draglimit: 1,
			
			//each file size must be less than 2.5Mb
			//filesize: 2621440,
			filesize: 5500621440,
			//total files size must not exceed 3.5Mb
			//maxsize: 3670016,
			maxsize: 5500621440,
			
			//use iframe
			iframe: false,
			
			//upload container id
			container: 'upload',
			
			//filter uploaded file type
			//filetype: 'html,rar,zip',
			
			//upload field name
			name: 'alias',
			//limit: 2, /* limit to two downloads */
			multiple: false, //enable multiple selection in file dialog
			progressbar: {

				width: 140, //fix the progressbar width
				color: '#000', 
				fillColor: '#fff',
				text: 'Pending...',
				onChange: function (value, progressbar) {
				
					//console.log(arguments)
					progressbar.setText('completed: ' + (100 * value).format() + '%')
				}
			},
		/*
			
			onCreate: function (transfer) {
			
				//do something
			},
		*/
			onAbort: function (object) {
			
				//alert('Upload aborted:\n' + object.message)
			},
			onCancel: function (obj) {
			
				//upload size
				/*
				$('infos').set('html', uploadManager.getSize('upload').toFileSize());
				if(obj.message) alert('Upload cancelled:\n' + obj.message)
				*/
				
			},
			onSuccess: function (infos) {
				
				//$('div.upload-container').destroy();
				//alert("Fuck");
				//$('upload').getElement('div.upload-container').destroy();
				//alert($('upload').getElement('div.upload-container').get('html'));
				//uploadManager.upload(options);
				//upload size
				//$('infos').set('html', uploadManager.getSize('upload').toFileSize());
				//console.log(infos.file);
				//download link
				//new Element('span', {style: 'display: none;', html: '<a href="upload.php?' + infos.path + '&dl=1&filename=' + infos.file + '">download</a> -&nbsp;'}).inject($(infos.transfer).getElement('a'), 'before')
			},
			onAllComplete: function (container)
			{
				$('upload').getLast('div.upload-container').setStyle('display', 'none');
				
				if (!uploadManager.getDragAndDrop())
					uploadManager.upload(options);
				else
				{
					var _div = $('upload').getLast('div.upload-container').getPrevious('div.upload-container').dispose();
					_div.inject($('upload'));
				}
					
				uploadManager.setDragAndDrop(false);
					
				//var _div = $('upload').getLast('div.upload-container').getPrevious('div.upload-container');
				//alert("fuck");
				
				//if (_div == null)
				//	_div = $('upload').getLast('div.upload-container');
				
				//_div.setStyle('display', 'none');
				
				//uploadManager.upload(options);
				
				//alert("fuck");
				/*var message = 'all transfers completed for "' + container + '"';
				
				if(window.console && console.log) console.log(message);
				else alert(message);*/
			}
		};
	
	uploadManager.attachDragEvents('upload', options);
	uploadManager.upload(options);
	/*document.getElement('a').addEvent('click', function(e) {
	
		e.stop();
		uploadManager.upload(options)
	});*/
	
	var tipsupload = new Tips($$('.tipsupload'), 
					{
						showDelay: 400,
						hideDelay: 400,
						text: "data-text",
						fixed: true,
						onShow: function(tip, el)
						{
							tip.addClass('tipfile');
							tip.setStyle('display', 'block');
						},
						onHide: function(tip, el)
						{
							tip.removeClass('tipfile');
							tip.setStyle('display', 'none');
						}
					});
	});
				</script>
				<div id="fileimage">
					<?php echo Form::open("", "post", array("id" => "form-avatar", "name" => "form-avatar")); ?>
						<div id="upload"></div>
					<?php echo Form::close(); ?>
					<div id="avatar" class="divfileimage" style="display: none;">
						<?php echo Html::img("upload/" . Auth::get('image'), "class: imgavatar"); ?>
					</div>
				</div>
			</td>
			<td class="td-logout"><?php echo  date("d/m/y"); ?><br /><?php echo Html::link("", 'text: ' . $config['application']['domain'], 'style: font-size: 8px; text-decoration: none;'); ?></td>
		</tr>
		<tr>
			<td class="td-logout" style="height: 10px;"><?php echo Html::link('profile', 'text: ' . ucfirst(_("edit profile"))); ?></td>
		</tr>
		<tr>
			<td class="td-logout" style="height: 10px;"><?php echo Html::link('login/logout', 'text: ' . ucfirst(_("sign out"))); ?></td>
		</tr>
	</table>

<?php
	}
	else
	{
		/* Vista parcial de inicio de sesión de usuario */
?>

<?php echo Form::open("login/login", "post", array("id" => "form-login", "name" => "form-login", "onsubmit" => "return sendForm(this, false, true);")); ?>
	<table class="table-loginF">
		<tr>
			<td><span><?php echo ucfirst(_("user")); ?>:</span></td>
			<td class="td-login"><?php echo Form::text("user", "class: texto"); ?></td>
		</tr>
		<tr>
			<td><span><?php echo ucfirst(_("password")); ?>:</span></td>
			<td class="td-login"><?php echo Form::password("password", "class: texto"); ?></td>
		</tr>
		<tr>
			<td colspan="2"><?php echo Form::submit(ucfirst(_("sign in")), "class: boton"); ?></td>
		</tr>
		<tr>
			<td colspan="2" class="table-td-left"><?php echo Html::link("register", ucfirst(_("sign up"))); ?></td>
		</tr>
		<tr>
			<td colspan="2" class="table-td-left"><a href=""><?php echo ucfirst(_("can't access account")); ?></a></td>
		</tr>
	</table>
<?php echo Form::close(); ?>

<?php	} ?>
